package com.example.beerhunterapp;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.ImageView;

public class ScanWindow extends Activity{

	Intent intentMenu;
	MediaPlayer mp1;
	
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.scan_activity);
        
        intentMenu = new Intent(this, MenuWindow.class);
        mp1 = MediaPlayer.create(this, R.raw.camera_click); 
        
        Button doScanButton = (Button) findViewById(R.id.doScanButton);
        doScanButton.setOnTouchListener(new OnTouchListener(){
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				if(event.getAction() == (MotionEvent.ACTION_UP)){
	                //Do whatever you want after press
					((ImageView) findViewById(R.id.duvel_picture)).setImageResource(R.drawable.scan_duvel2);
					mp1.start();
					InfoProtoypeSingleton.getInstance().setNumberOfBeer(3);
					startActivity(intentMenu);
					finish();
	            }
	            else{
	                //Do whatever you want during press  
	            	((ImageView) findViewById(R.id.duvel_picture)).setImageResource(R.drawable.scan_duvel1);        
	            }
	            return true;
			}
        	
        });
    }
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event)  {
        if (keyCode == KeyEvent.KEYCODE_BACK ) {
            // do something on back.
			startActivity(intentMenu);
			finish();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }    
	
}
